local hx__sanyin = fk.CreateSkill {
  name = "hx__sanyin",
}

hx__sanyin:addEffect(fk.Death, {
  anim_type = "control",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(hx__sanyin.name)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local targets = table.filter(room:getAlivePlayers(), function(p)
      return not p.dying and not p.dead
    end)
    local tos = room:askToChoosePlayers(player,{
      targets = targets,
      min_num = 1,
      max_num = 1,
      skill_name = hx__sanyin.name,
      prompt = "请选择一名选择执行选项的角色",
    })
    local choice = room:askToChoice(tos[1], {
      choices = {"回复一点体力", "摸两张牌"},
      prompt = "你可以执行一项",
      skill_name = hx__sanyin.name,
    })
    if choice == "回复一点体力" then
      room:recover({
        who = tos[1],
        num = 1,
        skillName = hx__sanyin.name
      })
    elseif choice == "摸两张牌" then
      tos[1]:drawCards(2, hx__sanyin.name)
    end
  end,
})


hx__sanyin:addEffect(fk.EnterDying, {
  anim_type = "control",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(hx__sanyin.name)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local targets = table.filter(room:getAlivePlayers(), function(p)
      return not p.dying and not p.dead
    end)
    local tos = room:askToChoosePlayers(player,{
      targets = targets,
      min_num = 1,
      max_num = 1,
      skill_name = hx__sanyin.name,
      prompt = "请选择一名选择执行选项的角色",
    })
    local choice = room:askToChoice(tos[1], {
      choices = {"回复一点体力", "摸两张牌"},
      prompt = "你可以执行一项",
      skill_name = hx__sanyin.name,
    })
    if choice == "回复一点体力" then
      room:recover({
        who = tos[1],
        num = 1,
        skillName = hx__sanyin.name
      })
    elseif choice == "摸两张牌" then
      tos[1]:drawCards(2, hx__sanyin.name)
    end
  end,
})

hx__sanyin:addEffect(fk.AfterDying, {
  anim_type = "control",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(hx__sanyin.name) and not target.dead
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local targets = table.filter(room:getAlivePlayers(), function(p)
      return not p.dying and not p.dead
    end)
    local tos = room:askToChoosePlayers(player,{
      targets = targets,
      min_num = 1,
      max_num = 1,
      skill_name = hx__sanyin.name,
      prompt = "请选择一名选择执行选项的角色",
    })
    local choice = room:askToChoice(tos[1], {
      choices = {"回复一点体力", "摸两张牌"},
      prompt = "你可以执行一项",
      skill_name = hx__sanyin.name,
    })
    if choice == "回复一点体力" then
      room:recover({
        who = tos[1],
        num = 1,
        skillName = hx__sanyin.name
      })
    elseif choice == "摸两张牌" then
      tos[1]:drawCards(2, hx__sanyin.name)
    end
  end,
})

return hx__sanyin